<template>
  <div id="container"
       style="height: 700px;width: 100%;border-top: 1px solid rgb(221, 221, 221); border-bottom: 1px solid rgb(221, 221, 221); ">
  </div>
</template>
<script>
  var map;
  export default {
    data () {
      return {
        mapstyle: {
          display: "none",
          width: "0",
          height: "0"
        },

        mapSearch: '',//地图搜索内容
        bottomPosition:"",//底部坐标
      }
    },
    components: {

    },
    mounted(){
      this.init();

      this.mapstyle = {
        position: "fixed",
        zIndex: "900",
        top: "170px",
        left: "20%",
        width: "60%",
        border: "1px solid #bbb",
        background: "#fff",
        borderRadius: "4px",
        boxShadow: "0 4px 8px rgba(0,0,0,0.25)",
      };
    },
    methods: {
      init() {
        var markers = [];
        var _this = this;
        var x=[];

          x=[113.69957809448242, 34.721554446276704]

        map = new AMap.Map('container', {
          resizeEnable: true,
          zoom:12,
          center: x,
        });
        if (_this.mapSearch != '') {
          AMap.service(["AMap.PlaceSearch"], function () {


            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
              pageSize: 5,
              pageIndex: 1,
              city: "0379", //城市
              map: map//,
              //panel: "panel"
            });

            //关键字查询
            placeSearch.search(_this.mapSearch, function (status, result) {


            });
          });
        }

        map.on('click', function (e) {
          map.remove(markers);
          _this.bottomPosition = e.lnglat.getLng() + ',' + e.lnglat.getLat();
          marker = new AMap.Marker({
            icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
            color:"red",
            position: _this.bottomPosition.split(",")
          });
          markers.push(marker);
          marker.setMap(map);
          //选完位置之后把值传给父组件

        });

      },

    }
  }
</script>
<style lang="less" scoped>

</style>